// packageA/mycomponent/goodsComponent/plugin/appointment/appointment.js
var app = getApp();
var location = require("../../../../../../mybehaviors/location/location");

Component({
  behaviors: [location],
  /**
   * 组件的属性列表
   */
  properties: {
    goodsId: {
      type: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    projects: [],
    appointmentLang: ''
  },
  lifetimes: {
    attached() {
      this.getProject();
      try {
        let info = wx.getStorageSync("yz_basic_info");
        if (info) {
          this.setData({
            appointmentLang: info.lang.appointment,
          });
        }
      } catch (err) {
        console.log(err);
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 预约项目请求
    getProject() {
      var that = this;
      let urlStr = app.getNetAddresss("plugin.appointment.frontend.project.get-list-by-goods-id");
      app._postNetWork({
        url: urlStr,
        data: {
          goods_id: that.data.goodsId
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            that.setData({
              projects: res.data,
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: "none",
            });
            console.log(res.msg);
          }
        },
      });
    },
    // 预约项目
    goProjectDetails(e) {
      let point = {};
      this._getLocation((mapdata, e) => {
        point = {
          lat: e.lat,
          lng: e.lng,
        }
        wx.navigateTo({
          url: "/packageE/appointment/ProjectDetails/ProjectDetails?project_id=" + id + '&point=' + JSON.stringify(point),
        });
      });
    },
 
    // 预约项目查看更多
    gotoProjects() {
      this.setData({
        showProjects: true,
      });
    },
    // 预约项目弹窗关闭
    ProjectsClose(e) {
      this.setData({
        showProjects: false,
      });
    },
  }
});